import { memberTotal, goodsTotal, orgTotal, dynamicTotal, memberAnalysis, statisticalAnalysis } from '@/api/member'

const total1 = [
  { api: memberTotal, key: 'memberTotal' },
  { api: goodsTotal, key: 'goodsTotal' },
  { api: orgTotal, key: 'orgTotal' },
  { api: dynamicTotal, key: 'dynamicTotal' }
]
const memberCanvs = [
  { title: '', name: 'canvas1' },
  { title: '', name: 'canvas2' },
  { title: '年龄分布', name: 'canvas3' },
  { title: '城市分布', name: 'canvas4' }
]
const organizeCanvs = [
  { title: '', name: 'canvas5' },
  { title: '行业分布', name: 'canvas6' },
  { title: '规模分布', name: 'canvas7' }
]
export function createOption(data, isLine) {
  const option = {
    series: [{
      type: 'pie',
      radius: ['55%', '70%'],
      emphasis: {
        scale: false
      },
      itemStyle: {
        borderRadius: 10,
        borderColor: '#fff',
        borderWidth: 2
      },
      label: {
        formatter: [
          '{bstyle|{b}}',
          '{dstyle|{d}%}'
        ].join('\n'),
        rich: {
          bstyle: {
            align: 'center',
            lineHeight: 20,
            color: '#999999'
          },
          dstyle: {
            lineHeight: 20,
            align: 'center'
          }
        }
      },
      data
    }]
  }
  if (!isLine) {
    option.series[0].labelLine = { show: false }
    option.series[0].label = { show: false }
  }
  return option
}
const total2 = [
  {
    api: memberAnalysis,
    idRender: true,
    transform(res) {
      const data1 = [
        { value: res.hasAuth, name: '已认证', itemStyle: { color: '#3ba1ff', borderRadius: 10 }},
        { value: res.notAuth, name: '未认证', itemStyle: { color: '#f0f2f5' }, borderRadius: 10 }
      ]
      memberCanvs[0].title = `<p style="margin: 0;">认证会员</p><p style="margin: 0;color: #454545;font-size: 18px;">${((res.hasAuth / (res.hasAuth + res.notAuth)*100)).toFixed(2)}%</p>`
      const data2 = [
        { value: res.man, name: '男', itemStyle: { color: '#69d389', borderRadius: 10 }},
        { value: res.woman, name: '女', itemStyle: { color: '#f0f2f5' }, borderRadius: 10 }
      ]
      memberCanvs[1].title = `<p style="margin: 0;">男女比例</p><p style="margin: 0;color: #454545;font-size: 18px;">${res.man}:${res.woman}</p>`
      const data3 = [
        { value: res.age1, name: '<18岁', itemStyle: { color: '#fcdb56', borderRadius: 10 }},
        { value: res.age2, name: '18~40岁', itemStyle: { color: '#e04358' }, borderRadius: 10 },
        { value: res.age3, name: '>40岁', itemStyle: { color: '#66cf86' }, borderRadius: 10 }
      ]
      const data4 = []
      const color = ['#66cf86', '#45bbf1', '#e14358', '#fcdb56']
      for (let i = 1; i < 5; i++) {
        if (res['city' + i]) {
          data4.push({ value: res['city' + i].value, name: res['city' + i].key, itemStyle: { color: color[i - 1], borderRadius: 10 }})
        }
      }
      return [
        { option: createOption(data1), key: 'canvas1' },
        { option: createOption(data2), key: 'canvas2' },
        { option: createOption(data3, true), key: 'canvas3' },
        { option: createOption(data4, true), key: 'canvas4' }
      ]
    }
  },
  {
    api: statisticalAnalysis,
    idRender: true,
    transform(res) {
      const data1 = [
        { value: res.hasAuth, name: '已认证', itemStyle: { color: '#3ba1ff', borderRadius: 10 }},
        { value: res.notAuth, name: '未认证', itemStyle: { color: '#f0f2f5' }, borderRadius: 10 }
      ]
      organizeCanvs[0].title = `<p style="margin: 0;">认证组织</p><p style="margin: 0;color: #454545;font-size: 18px;">${((res.hasAuth / (res.hasAuth + res.notAuth)*100)).toFixed(2)}%</p>`
      const data2 = []
      const data3 = []
      const color = ['#66cf86', '#45bbf1', '#e14358', '#fcdb56']
      res.industry.forEach((item, index) => {
        data2.push({ value: item.value, name: item.key||'其他', itemStyle: { color: color[index], borderRadius: 10 }})
      })
      res.staff.forEach((item, index) => {
        data3.push({ value: item.value, name: item.key||'其他', itemStyle: { color: color[index], borderRadius: 10 }})
      })
      return [
        { option: createOption(data1), key: 'canvas5' },
        { option: createOption(data2, true), key: 'canvas6' },
        { option: createOption(data3, true), key: 'canvas7' }
      ]
    }
  }
]
// 会员统计导出数据表头
const memberGrow = ['日期','增长人数']
const genderGrow = ['日期','男会员增长数','女会员增长数']
const ageGrow = ['日期','18岁会员增长数','18岁~40岁会员增长数','>18岁会员增长数']
const areaGrow = ['城市编码','城市','增长人数']

export function memberXlxsHeader() {
   return  {memberGrow,genderGrow,ageGrow ,areaGrow }
}

// 组织统计导出数据表头
const organizationGrow = ['日期','组织增长量']
const scaleGrow = ['日期','<50人组织增长数','50~500人组织增长数','>500人组织增长数']
const industryGrow = ['行业编码','行业','增长人数']
export function organizationXlxsHeader() {
   return  {organizationGrow,scaleGrow,industryGrow  }
}

// 动态统计导出数据表头
const dynamicPublishGrow = ['日期','动态发布量']
const dynamicDataGrow = ['日期','动态浏览数','点赞数','评论数','转发数']

export function dynamicXlxsHeader() {
   return  {dynamicPublishGrow,dynamicDataGrow}
}

// 商品统计导出数据表头
const goodsPublish = ['日期','商品发布量']
const goodsData = ['日期','商品浏览量or咨询量']
export function goodsXlxsHeader() {
   return  {goodsPublish,goodsData}
}


export default function useConfig() {
  const realTimeData = [
    { label: 'memberTotal', icon: 'el-icon-user-solid', value: '会员总数' },
    { label: 'orgTotal', icon: 'el-icon-user', value: '组织总数' },
    { label: 'dynamicTotal', icon: 'el-icon-s-home', value: '动态总数' },
    { label: 'goodsTotal', icon: 'el-icon-s-shop', value: '商品总数' }
  ]
  return { realTimeData, total1, total2, memberCanvs, organizeCanvs  }
}

